package com.woniu.controller;

import com.woniu.entity.Staff;
import com.woniu.service.StaffService;
import com.woniu.service.UserService;
import com.woniu.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/staff")
public class StaffController {
    @Resource
    private StaffService staffService;
    @GetMapping("/findAll")
    public ResponseUtil selectAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){
        return staffService.selectAll(pageNum,pageSize);
    }
//    @GetMapping("/findStaffs")
//    public ResponseUtil findStaffs(){
//        return staffService.findStaffs();
//    }

    @GetMapping("/list")
    public ResponseUtil selectByCondition(@RequestParam(required = false) String name,@RequestParam(required = false) String deptName,@RequestParam(required = false) String roomName,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        return staffService.selectByCondition(name,deptName,roomName,pageNum,pageSize);
    }
    @PostMapping("/del")
    public ResponseUtil updateStaff(Integer id){
        return staffService.updateStaff(id);
    }
    @PostMapping("/insert")
    public ResponseUtil insertSelective(@RequestBody Staff record){
        return staffService.insertSelective(record);
    }
    @PostMapping("/update")
    public ResponseUtil updateByPrimaryKeySelective(@RequestBody Staff record) {
        return staffService.updateByPrimaryKeySelective(record);
    }
    @PostMapping("/login")
    public ResponseUtil login(@RequestBody Staff staff) throws Exception{
        return staffService.login(staff.getStaffNo(),staff.getPassword());
    }
    @GetMapping("/selectAll")
    public ResponseUtil findAll(){
        return staffService.findAll();
    }
}
